package vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import controlador.Sistema;
import controlador.Utils;



public class HsUsuarios extends javax.swing.JFrame {
	
	private static final long serialVersionUID = 1L;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JComboBox comboTarea;
	private JButton jButton1;
	private JTextField fieldFecha;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private Logo jPanel1;
	private JLabel labelResult;
	private JTextField fieldHoras;
	private JLabel jLabel3;
	private JButton jButton2;
	private static HsUsuarios instancia;

	private HsUsuarios() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			final String[] tareas = Sistema.getInstancia().buscarNombreTareasUsuario(Utils.getIdUsuario());
			this.setTitle("Carga de Horas");
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Carga de Horas");
				jLabel1.setBounds(91, 78, 144, 16);
				jLabel1.setFont(new java.awt.Font("Segoe UI",1,14));
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Aceptar");
				jButton2.setBounds(69, 247, 85, 23);
				jButton2.setBackground(new java.awt.Color(255,255,255));
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						String tarea = tareas[comboTarea.getSelectedIndex()];
						Long idTarea = Sistema.getInstancia().buscarIdTarea(tarea);
						String fecha = fieldFecha.getText();
						int horas = Integer.parseInt(fieldHoras.getText());
						long idEmp = Utils.getIdUsuario();
						Sistema.getInstancia().cargarHoras(idTarea,horas,fecha,idEmp);
						labelResult.setText(Utils.getResultado());
					}
				});
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Tarea:");
				jLabel3.setBounds(23, 114, 46, 16);
			}
			{
				ComboBoxModel jComboBox1Model = 
					new DefaultComboBoxModel(tareas);
				comboTarea = new JComboBox();
				getContentPane().add(comboTarea);
				comboTarea.setModel(jComboBox1Model);
				comboTarea.setBounds(73, 111, 202, 23);
				comboTarea.setBackground(new java.awt.Color(255,255,255));
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Hs:");
				jLabel2.setBounds(23, 146, 21, 16);
			}
			{
				fieldHoras = new JTextField();
				getContentPane().add(fieldHoras);
				fieldHoras.setBounds(73, 143, 202, 23);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Cerrar");
				jButton1.setBounds(165, 247, 85, 23);
				jButton1.setBackground(new java.awt.Color(255,255,255));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton1.actionPerformed, event="+evt);
						System.out.println("botonCancelar.actionPerformed, event="+evt);
						Bienvenida b = Bienvenida.getinstancia(); 
						b.setLocationRelativeTo(null);
						b.setVisible(true);
						dispose();
					}
				});
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("Fecha:");
				jLabel4.setBounds(23, 181, 46, 14);
			}
			{
				fieldFecha = new JTextField();
				getContentPane().add(fieldFecha);
				getContentPane().add(getJLabel5());
				getContentPane().add(getLabelResult());
				getContentPane().add(getJPanel1());
				fieldFecha.setBounds(74, 178, 202, 23);
			}
			pack();
			this.setSize(316, 420);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static HsUsuarios getinstancia() {
		if(instancia == null)
			return new HsUsuarios();
		return instancia;
	}
	
	private JLabel getJLabel5() {
		if(jLabel5 == null) {
			jLabel5 = new JLabel();
			jLabel5.setText("Formato aaaa-mm-dd");
			jLabel5.setBounds(74, 205, 201, 16);
			jLabel5.setFont(new java.awt.Font("Segoe UI",2,12));
		}
		return jLabel5;
	}
	
	private JLabel getLabelResult() {
		if(labelResult == null) {
			labelResult = new JLabel();
			labelResult.setBounds(12, 278, 276, 76);
		}
		return labelResult;
	}
	
	private Logo getJPanel1() {
		if(jPanel1 == null) {
			jPanel1 = new Logo(false);
			jPanel1.setBounds(61, 22, 189, 50);
		}
		return jPanel1;
	}

}
